﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using Imaginecup.shareData;

namespace Imaginecup.util.input
{
    public interface IPhoneInputHandler
    {
        TouchCollection GetCurrentTouch();
        TouchCollection GetPrevTouch();
    }

    public class PhoneInputHandler : GameComponent, IPhoneInputHandler
    {
        private static PhoneInputHandler m_InputHandler = null;
        
        private TouchCollection m_CurrentTouchCollection;   //현재 터치 패널상태
        private TouchCollection m_PrevTouchCollection;      //이전 터치 패널상태.

        private PhoneInputHandler()
            : base(StateShareData.GetShareData().GetGame())
        {
            m_PrevTouchCollection = TouchPanel.GetState();
            m_CurrentTouchCollection = TouchPanel.GetState();
        }

        
        public static IPhoneInputHandler GetInputHandler()
        {
            if (m_InputHandler == null)
            {
                m_InputHandler = new PhoneInputHandler();
            }
            return m_InputHandler;
        }

        // 입력장치에 관한 업데이트
        public override void Update(GameTime gameTime)
        {
            m_PrevTouchCollection = m_CurrentTouchCollection;
            m_CurrentTouchCollection = TouchPanel.GetState();
        }

       
        public TouchCollection GetCurrentTouch()
        {
            return m_CurrentTouchCollection;
        }

        public TouchCollection GetPrevTouch()
        {
            return m_PrevTouchCollection;
        }
    }
}
